package com.kfyang.manualgear.util;

import com.squareup.javapoet.ClassName;

import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror;

public interface ClassUtils {
    /**
     * 从 TypeMirror 转换为 TypeElement
     * @param mirror TypeMirror
     * @return TypeElement
     */
    static TypeElement mirrorToType(TypeMirror mirror) {
        return (TypeElement) ((DeclaredType) mirror).asElement();
    }

    /**
     * 从类全名转换为 ClassName
     * @param className 类全名
     * @return ClassName
     */
    static ClassName strToClass(String className) {
        int divideIndex = className.lastIndexOf('.');
        return ClassName.get(className.substring(0, divideIndex), className.substring(divideIndex + 1));
    }
}
